function stat = ldatest(stego, cover, ntrain, ntest, loop, verbose)
    if nargin < 6
        verbose = 1;
    end
    [s1, h1] = size(stego);
    [s2, h2] = size(cover);
    ntrain = ntrain / 2;
    ntest = ntest / 2;
    if (ntrain+ntest > s1) || (ntrain + ntest > s2)
        error('number of training and testing samples must less than %d and %d.', s1, s2);
    end
    if h1 ~= h2
        error('dimension of stego / cover does not match.');
    end
    
    sacc = 0;
    for i = 1:loop
        if verbose
            fprintf('round %d:\n',i);
        end
        p1 = randperm(s1);
        p2 = randperm(s2);
        tic;
        model = ldaclassify(stego(p1(1:ntrain),:),cover(p2(1:ntrain),:));
        toc;
        lbl = [ones(ntest,1);zeros(ntest,1)];
        tst = [stego(p1(ntrain+1:ntrain+ntest),:);cover(p2(ntrain+1:ntrain+ntest),:)];
        [~, acc, ~] = ldapredict(lbl, tst, model);
        if verbose
            fprintf('acc = %g\n',acc);
        end
        sacc = sacc + acc;
    end
    sacc = sacc / loop;
    stat = struct('acc', sacc, 'ntrain', ntrain, 'ntest', ntest, ...
        'loop', loop, 'stego', size(stego), 'cover', size(cover));
    fprintf('average accuracy = %g\n',sacc);
end
